package com.briup.mt.service.impl;

import com.briup.mt.bean.*;
import com.briup.mt.dao.BaseUserRoleMapper;
import com.briup.mt.service.IBaseUserRoleService;
import com.briup.mt.service.IBaseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Layla
 * @version 1.0
 * @date 2020/12/16 11:08
 */
@Service
public class BaseUserRoleServiceImpl implements IBaseUserRoleService {
    @Resource
    private BaseUserRoleMapper baseUserRoleMapper;

    @Override

    public List<BaseUserRole> query(Long userId) {
        BaseUserRoleExample example=new BaseUserRoleExample();
        if (!StringUtils.isEmpty(userId)){
            example.createCriteria().andUserIdEqualTo(userId);
        }
        return  baseUserRoleMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(BaseUserRole baseUserRole) {
        if (baseUserRole.getId() == null) {
            baseUserRoleMapper.insert(baseUserRole);
        }else{
            baseUserRoleMapper.updateByPrimaryKey(baseUserRole);
        }
    }

    @Override
    public void deleteById(long id) {

        baseUserRoleMapper.deleteByPrimaryKey(id);
    }
}

